package com.hhkj.generator.common;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.hhkj.generator.entity.ExcelFieldItem;
import com.hhkj.generator.entity.TableItem;
import com.hhkj.generator.util.PathUtil;

import java.io.File;
import java.util.List;

public class ExcelFileReader {

    public static List<ExcelFieldItem> read(String fileName){
        File file = new File(fileName);
        ImportParams importParams = new ImportParams();
        importParams.setTitleRows(0);
        List<ExcelFieldItem> questionList = ExcelImportUtil.importExcel(file, ExcelFieldItem.class, importParams);
        return questionList;
    }

    public static void main(String[] args) throws Exception {
        String fileName = PathUtil.getClassResources() + "/demo1.xlsx";

        List<ExcelFieldItem> fieldList = read(fileName);

        FieldList2TableItemParser parser = new FieldList2TableItemParser();
        List<TableItem> tableList = parser.parse(fieldList);

        String targetPath = PathUtil.getClasspath() + "study";

        for (TableItem tableItem : tableList) {
            CreateCodeUtil.createCode(tableItem, "study", targetPath,"D:/sql");
        }

        System.out.println(tableList);
    }

}
